from utils import restful
from django.shortcuts import redirect,reverse
from functools import wraps
from django.http import Http404
def xfz_login_required(func):
    def warpper(request,*args,**kwargs):
        if request.user.is_authenticated:
            return func(request,*args,**kwargs)
        else:
            if request.is_ajax():
                return restful.auth_error(message="请先登录")
            else:
                return redirect(reverse('news:index'))
    return warpper

def xfz_superuser_required(viewfunc):
    @wraps(viewfunc)
    def decorator(request,*args,**kwargs):
        if request.user.is_superuser:
            return viewfunc(request,*args,**kwargs)
        else:
            raise Http404()

    return decorator